package com.ankang.art.controller;

import com.ankang.art.dto.AvgDto;
import com.ankang.art.dto.JudgesDto;
import com.ankang.art.dto.TestIds;
import com.ankang.art.pto.JudgesPto;
import com.ankang.art.service.JudgesService;
import com.ankang.art.vo.Judges;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:
 * Date:2020/3/17    19:41
 */
@RestController
@RequestMapping("/art/management/sts")
@CrossOrigin
public class JudgesController {

    @Autowired
    JudgesService judgesService;

    @GetMapping("/deleteJudges")
    public ResponseEntity deletedResult(@RequestParam(value = "name") String name){

        if(null == name){
            throw new RuntimeException("id不能为空");
        }

        judgesService.deleteJudges(name);

        return new ResponseEntity(HttpStatus.OK);
    }
    @GetMapping("/getJudges")
    public ResponseEntity getJudges(@RequestParam(value = "name",required = false) String name,
                                    @RequestParam(value = "status",required = false) String status,
                                    @RequestParam(value = "schoolName",required = false) String schoolName,
                                    @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                                    @RequestParam(value = "pageSize" ,defaultValue = "10") Integer pageSize){

        PageHelper.startPage(pageNo, pageSize);

        return new ResponseEntity(judgesService.getJudges(name,status , schoolName),HttpStatus.OK);
    }

    @PostMapping("/savaJudges")
    public ResponseEntity savaJudges(@RequestBody JudgesPto judgesPto){



        judgesService.savaJudges(judgesPto);

        return new ResponseEntity(HttpStatus.OK);
    }

    @PostMapping("/updateJudges")
    public ResponseEntity updateJudges(@RequestBody JudgesDto judgesDto){


        judgesService.updateJudges(judgesDto);

        return new ResponseEntity(HttpStatus.OK);
    }



    @GetMapping("login")
    public ResponseEntity login(@RequestParam(value = "name")String name,
                                @RequestParam(value = "password")String password) throws Exception {

        Judges judges = judgesService.login(name,password);
      /*  if(null == judges){
            throw new Exception("账号或密码错误");

        }*/
        return new ResponseEntity(judges,HttpStatus.OK);
    }
    @GetMapping("getStudent")
    public ResponseEntity getStudent(){

        return new ResponseEntity(judgesService.getExamineess(),HttpStatus.OK);
    }

    @PostMapping("addAvg")
    public ResponseEntity getStudentss(@RequestBody List<AvgDto> avgDtos){

        for (AvgDto avgDto : avgDtos) {
            judgesService.getAvg(avgDto);
        }

        return new ResponseEntity(HttpStatus.OK);
    }

    @GetMapping("getTeachers")
    public ResponseEntity getTeachers(@RequestParam(value = "testId")Integer testId){

        return new ResponseEntity(judgesService.getTeachers(testId),HttpStatus.OK);
    }

    @GetMapping("/getExamTeachers")
    public ResponseEntity getExamTeachers(){



        return new ResponseEntity(judgesService.getExamTeachers(),HttpStatus.OK);
    }

    @PostMapping("/addExamTeachers")
    public ResponseEntity addExamTeachers(@RequestBody TestIds testIds){

        judgesService.addExamTeachers(testIds);
        return new ResponseEntity(HttpStatus.OK);
    }

    @GetMapping("/beginTest")
    public ResponseEntity beginTest(@RequestParam(value = "testId") Integer testId){

        Boolean flag =  judgesService.beginTest(testId);
        return new ResponseEntity(HttpStatus.OK);

    }
}
